import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/enum_entity.dart';
import 'package:library_base/entities/purchase_order_entity.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/res/widget_generator.dart';
import 'package:get/get.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/button/ink_bg_well.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


Widget filterWell(
    String paymentStatus,{
      Function(String)? showFiltration,
      Callback2<String, String>? onTap,
    }) {
  return inkBgWell(
    child: Container(
        padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 24.w),
        child:
        LocalImage('admin_filter', package: Constant.packAdmin(), width: 38.w, height: 38.w)),
    onTap: () => showFiltration?.call(paymentStatus),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}


Widget buildItem(
  PurchaseOrderEntity purchaseOrderEntity, {
  Function(PurchaseOrderEntity purchaseOrderEntity)? onPaymentApplication,
  Function(PurchaseOrderEntity purchaseOrderEntity)? onCorrectionOrder,
  Function(PurchaseOrderEntity purchaseOrderEntity)? onItemClick,
}) {
  return GestureDetector(
    onTap: (){
      onItemClick?.call(purchaseOrderEntity);
    },
    child: roundWidget(
      width: double.infinity,
      margin: edgeLR24,
      decoration: rs8,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: edgeAll24,
            child: Row(children: [
              Expanded(
                child: Text(
                  purchaseOrderEntity.purchaseOrderNumber,
                  style: normalTextColor28,
                ),
              ),
              Text(statusText(purchaseOrderEntity), style: statusTextStyle(purchaseOrderEntity)),
            ]),
          ),
          line1,
          Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              gapH18,
              Padding(
                padding: edgeLR24,
                child: Row(
                  children: [
                    Text(
                      "${MultiLanguage.purchaseAmount.tr}:",
                      style: normalTextColor28,
                    ),
                    Expanded(
                      child: Text(
                        "${purchaseOrderEntity.purchaseAmount}${MultiLanguage.yuan.tr}",
                        style: normalTextColor28,
                      ),
                    ),
                  ],
                ),
              ),
              gapH18,
              Padding(
                padding: edgeLR24,
                child: Row(
                  children: [
                    Text(
                      "${MultiLanguage.commodityQuantity.tr}:",
                      style: normalTextColor28,
                    ),
                    Expanded(
                      child: Text(
                        "${purchaseOrderEntity.purchaseCount}",
                        style: normalTextColor28,
                      ),
                    ),
                  ],
                ),
              ),
              gapH18,
              Padding(
                padding: edgeLR24,
                child: Row(
                  children: [
                    Text(
                      "${MultiLanguage.purchaseTime.tr}:",
                      style: normalTextColor28,
                    ),
                    Expanded(
                      child: Text(
                        purchaseOrderEntity.purchaseTime,
                        style: normalTextColor28,
                      ),
                    ),
                  ],
                ),
              ),
              gapH18,
              Padding(
                padding: edgeLR24,
                child: Row(
                  children: [
                    Text(
                      "${MultiLanguage.supplierNew.tr}:",
                      style: normalTextColor28,
                    ),
                    Expanded(
                      child: Text(
                        purchaseOrderEntity.supplierName,
                        style: normalTextColor28_2,
                      ),
                    ),
                  ],
                ),
              ),
              Visibility(
                  visible: visible(purchaseOrderEntity),
                  child: gapH18),
              Visibility(
                  visible: visible(purchaseOrderEntity),
                  child: line1),
              Visibility(
                  visible: visible(purchaseOrderEntity),
                  child: gapH24),
              Visibility(
                visible: visible(purchaseOrderEntity),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      //订单修正按钮
                  GradientButton(
                    ThemeUtil.getTheme(),
                    decoration: BoxDecoration(
                        borderRadius: const BorderRadius.all(Radius.circular(20)),
                        border: Border.fromBorderSide(
                            BorderSide(color: ThemeUtil.getTheme().sixthTextColor())),
                        color: ThemeUtil.getTheme().colorScheme.secondary),
                    padding: edgeV20H30 as EdgeInsets,
                    textStyle: normalTextColor26,
                    text: MultiLanguage.correctionOfOrder.tr,
                    normalColor: ThemeUtil.getTheme().colorScheme.secondary,
                    normalTextColor: ThemeUtil.getTheme().normalTextColor(),
                    onPressed: () {
                      onCorrectionOrder?.call(purchaseOrderEntity);
                    },
                  ),
                  gapW18,
                  //付款申请按钮
                  GradientButton(
                    ThemeUtil.getTheme(),
                    decoration: BoxDecoration(
                        borderRadius: const BorderRadius.all(Radius.circular(20)),
                        border: Border.fromBorderSide(
                            BorderSide(color: ThemeUtil.getTheme().fourthTextColor())),
                        color: ThemeUtil.getTheme().colorScheme.secondary),
                    padding: edgeV20H30 as EdgeInsets,
                    textStyle: transparentTextColor26,
                    text: MultiLanguage.paymentApplication.tr,
                    normalColor: ThemeUtil.getTheme().colorScheme.secondary,
                    normalTextColor: ThemeUtil.getTheme().fourthTextColor(),
                    onPressed: () {
                      onPaymentApplication?.call(purchaseOrderEntity);
                    },
                  ),
                  gapW24,
                ]),
              ),
              gapH24,
            ],
          ),
        ],
      ),
    ),
  );
}

TextStyle statusTextStyle(PurchaseOrderEntity purchaseOrderEntity) {
  if (purchaseOrderEntity.payStatus == PaymentStatus.NOT_PAY.name) {
    return fourthTextColor28;
  } else if (purchaseOrderEntity.payStatus == PaymentStatus.APPLICATION_PAYMENT.name) {
    return eighthTextColor28;
  } else {
    return primaryTextColor28;
  }
}

String statusText(PurchaseOrderEntity purchaseOrderEntity) {
  if (purchaseOrderEntity.payStatus == PaymentStatus.NOT_PAY.name) {
    return MultiLanguage.notApplied.tr;
  } else if (purchaseOrderEntity.payStatus == PaymentStatus.APPLICATION_PAYMENT.name) {
    return MultiLanguage.applying.tr;
  } else {
    return MultiLanguage.paymentReceived.tr;
  }
}

bool visible(PurchaseOrderEntity purchaseOrderEntity) {
  return purchaseOrderEntity.payStatus == PaymentStatus.NOT_PAY.name;
}
